package cn.com.ethos.search.drupal;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;

import cn.com.ethos.search.DbSetting;
import cn.com.ethos.search.index.DbRowStream;

public class NodeStream extends DbRowStream {

	public NodeStream(DbSetting settings) {
		super(settings);
	}

	@Override
	protected Document getDocument(ResultSet cursor) throws SQLException{
		if(cursor != null) {
			String subject = cursor.getString("title");
			String body    = cursor.getString("body");
			long nid       = cursor.getLong("nid");
			
			Document doc = new Document();
			doc.add(new Field("nid", String.valueOf(nid),Store.YES,Index.NO));
			doc.add(new Field("type","node",Store.YES,Index.NO));
			doc.add(new Field("content",body,Store.NO,Index.TOKENIZED));
			
			Field field = new Field("title",subject,Store.YES,Index.TOKENIZED);
			field.setBoost(TITLE_BOOST_VALUE);
			doc.add(field);
			return doc;	
		}
		return null;
	}

	@Override
	protected String getQuerySql() {
		return "select nid,title,body from node_revisions";
	}
}
